cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0048 NEW)
project(dyncli VERSION 0.1.0.0)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-function")

# options
option(DEBUG "enable debug" ON)
option(CONNLOG	"enable connection log" OFF)

option(SANITIZE "enable sanitize" OFF)
if(SANITIZE STREQUAL "ON")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
endif()

# include aux cmake scripts
include("../cmake/Gengetopt.cmake")
ADD_GENGETOPT_FILES(CMDLINE cmdline.ggo)
include("../cmake/Findlibev.cmake")
set (EXTRALIB ${LIBEV_LIBRARY})

include_directories("${CMAKE_CURRENT_BINARY_DIR}"
	"${PROJECT_BINARY_DIR}"
	"${LIBEV_INCLUDE_DIRS}"
	"${PROJECT_SOURCE_DIR}/../include"
	)

set(DYNCLI
main.c
../lib/buffer.c
../lib/arg.c
../lib/common.c
../lib/netutils.c
../lib/ip-address.c
)

find_package(CURL)
if(CURL_FOUND)
set (EXTRALIB ${EXTRALIB} ${CURL_LIBRARIES})
set(DYNCLI
	${DYNCLI}
	http.c
	)
endif()


set (STAGING_DIR $(STAGING_DIR))

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
	"${PROJECT_SOURCE_DIR}/config.h.in"
	"${PROJECT_BINARY_DIR}/config.h"
	)

# target
add_executable(dyncli ${CMDLINE} ${DYNCLI})
target_link_libraries(dyncli ${EXTRALIB} m)

# install
install(TARGETS dyncli DESTINATION bin)
